from pydub import AudioSegment
import os

# 输入输出目录
input_dir = './input_wav'
output_dir = './output_mp3'

# 创建输出目录
if not os.path.exists(output_dir):
    os.makedirs(output_dir)

# 批量转换
for filename in os.listdir(input_dir):
    if filename.endswith(".wav"):
        wav_path = os.path.join(input_dir, filename)
        mp3_path = os.path.join(output_dir, f"{os.path.splitext(filename)[0]}.mp3")
        sound = AudioSegment.from_wav(wav_path)
        sound.export(mp3_path, format="mp3")
        print(f"Converted {filename} to MP3")

